//import CostItem from "../controller/ui/cost_items"

import { Skill } from "../class/skill"
import JsonManager from "../manager/json_manager"
import MainManager from "../manager/main_manager"
import StorageManager from "../manager/storage_manager"
import UIManager from "../manager/ui_manager"
import { Config } from "../utils/config"
import { Emitter } from "../utils/emmiter"
import { MessageType } from "../utils/message"
import { Utils } from "../utils/utils"
import SkillDetailUIManager from "./skill_detail_ui_manager"

// import UIAnimaManager from "../manager/action_manager"

const { ccclass, property } = cc._decorator

interface OkCalBack {
    (isOK: boolean, param?: {}): void
}

@ccclass
export default class SkillListUIManager extends cc.Component {
    static instance: SkillListUIManager = null

    @property(cc.Node)
    uiNode: cc.Node = null

    @property(cc.Node)
    maskNode: cc.Node = null

    @property(cc.Label)
    labelTitle: cc.Label = null

    @property(cc.Label)
    labelDesc: cc.Label = null

    @property(cc.Button)
    btn1: cc.Button = null


    @property(cc.Button)
    btn2: cc.Button = null

    @property(cc.Button)
    btn3: cc.Button = null

    @property(cc.Button)
    btn4: cc.Button = null
   
    @property(cc.Button)
    buttonConfirm: cc.Button = null

    @property(cc.Button)
    closebtn: cc.Button = null

    @property(cc.Label)
    curLevelLable: cc.Label = null
  

    curCallBack: OkCalBack = null
    curParam: any = null


    _isClick: boolean = false

    onLoad() {
        SkillListUIManager.instance = this

        this.maskNode.on('click', this.hideUI, this);

        this.btn1.node.on("click",()=>{
            this.selectNextLeve(3)
        } , this)
        this.btn2.node.on("click",()=>{
            this.selectNextLeve(5)
        } , this)
        this.btn3.node.on("click",()=>{
            this.selectNextLeve(7)
        } , this)
        this.btn4.node.on("click",()=>{
            this.selectNextLeve(11)
        } , this)
        // this.closebtn.node.on("click",()=>{
        //     this.hideUI()
        // } , this)
        
        
        this.buttonConfirm.node.on("click", this.enterGame, this)

        if (this.uiNode.active) {
            this.uiNode.active = false
        }
    }



    showUI(title: string, desc: string, callback: OkCalBack = null, param: {} = null, isNormal: boolean = true, labels: string[] = null) {
        if (!this.uiNode.active) {
            this.uiNode.active = true
            //  UIAnimaManager.instance.showDialog(this.uiNode, this.maskNode)
        }


        // this.refreshUI()
        this.curParam = param
    }

    refreshUI(){
        this.curLevelLable.string = '第'+StorageManager.instance.levelInfo.curLevel+'关';
    }

    selectNextLeve(id:number){
        cc.log("点击id:"+id)
        UIManager.instance.openUI(SkillDetailUIManager, { name: Config.uiName.skillDetial,param: [id]},)
    }

    selectPreLeve(){
        StorageManager.instance.levelInfo.curLevel--;
        if(StorageManager.instance.levelInfo.curLevel<1){
            StorageManager.instance.levelInfo.curLevel=1;
        }
        this.refreshUI()
    }

    enterGame() {
        cc.log('1')
        // StorageManager.instance.skills.push(this.ids[0])
        // this.notifyAdd()
        Emitter.fire(MessageType.gameStart)
        this.hideUI()
    }

    

    

    confirm() {
     
        this.hideUI()
    }
    hideUI() {
        this.uiNode.active = false
        cc.director.resume();
        //  AudioManager.instance.playAudio('ui_close')

    }
}
